/* $Id: EditTeamDialog.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.gui.view;

import java.awt.Component;
import java.awt.Frame;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import org.jugger.tournament.gui.view.EditTeamPanel.EditTeamListener;
import org.jugger.tournament.model.Team;

import util.I18N;



public class EditTeamDialog extends JDialog implements EditTeamListener {

	private static final long serialVersionUID = 4330465190718427519L;

	private static EditTeamDialog dialog;
    private static Team value;
    private EditTeamPanel panel;

    /**
     * Set up and show the dialog.  The first Component argument
     * determines which frame the dialog depends on; it should be
     * a component in the dialog's controlling frame. The second
     * Component argument should be null if you want the dialog
     * to come up with its left corner in the center of the screen;
     * otherwise, it should be the component on top of which the
     * dialog should appear.
     */
    public static Team showDialog(Team team, Component frameComp,
                                    Component locationComp) {
    	value = null;

        Frame frame = JOptionPane.getFrameForComponent(frameComp);
        dialog = new EditTeamDialog(team, frame,
                                locationComp);
        dialog.setVisible(true);
        return value;
    }

    private EditTeamDialog(Team team, Frame frame,
                       Component locationComp) {
        super(frame, I18N.__("editTeam"), true);
        panel = new EditTeamPanel(team);
        panel.addEditTeamListener(this);
        add(panel);

        pack();
        setSize(350, 180);
        setLocationRelativeTo(locationComp);
    }

	public void performTeamEdited(Team team) {
		value = team;
		this.setVisible(false);
	}

	public void performAbort() {
		setVisible(false);
	}
}
